# $Id$
prefix=@prefix@
CFLAGS = @CFLAGS@

CFLAGS += -I. -I..

LIBDIR  = $(prefix)/lib/unicon
LD      = gcc $(CFLAGS)
RM      = rm -f
INSTALL = install -c

GROUP = root

EXECPROGS = cin2tab tab2cin cin2dat tab2dat txt2tab txt2tab1 tab2txt tab2txt1 

PROGS = $(EXECPROGS) \
        pinyin.tab.lx shuangpin.tab wubi.tab ziranma.tab \
        pinyin.tab.lx shuangpin.tab.lx wubi.tab.lx ziranma.tab.lx \
        pinyin.tab.phr shuangpin.tab.phr wubi.tab ziranma.tab.phr \
	sysphrase.tab usrphrase.tab
PROGS+=	phone.def cj.def array30.def stroke.def asx.def

all: $(PROGS)

pinyin.tab pinyin.tab.lx pinyin.tab.phr: cin2tab pinyin.cin
	./cin2tab pinyin

shuangpin.tab shuangpin.tab.lx shuangpin.tab.phr: cin2tab shuangpin.cin
	./cin2tab shuangpin

wubi.tab wubi.tab.lx wubi.tab.phr: cin2tab wubi.cin
	./cin2tab wubi

ziranma.tab ziranma.tab.lx ziranma.tab.phr: cin2tab ziranma.cin
	./cin2tab ziranma

cin2tab: cin2tab.c
	$(LD) -o cin2tab cin2tab.c

tab2cin: tab2cin.c
	$(LD) -o tab2cin tab2cin.c

cin2dat: cin2dat.c
	$(LD) -o cin2dat cin2dat.c

tab2dat: tab2dat.c
	$(LD) -o tab2dat tab2dat.c

txt2tab: txt2tab.c
	$(LD) -o txt2tab txt2tab.c

txt2tab1: txt2tab1.c
	$(LD) -o txt2tab1 txt2tab1.c

tab2txt: tab2txt.c
	$(LD) -o tab2txt tab2txt.c

tab2txt1: tab2txt1.c 
	$(LD) -o tab2txt1 tab2txt1.c

sysphrase.tab: sysphrase.txt pinyin.map txt2tab
	./txt2tab sysphrase.txt sysphrase.tab

usrphrase.tab: usrphrase.txt pinyin.map txt2tab1
	./txt2tab1 usrphrase.txt usrphrase.tab
	
depend .depend:
	$(CC) $(CFLAGS) -M *.c > .depend

clean:
	rm -f $(EXECPROGS)
	rm -f core *.o a.out *.bak *~
	rm -f *.tab *.tab.lx *.tab.phr *.idx *.dat

distclean:clean
	rm -f Makefile tags TAGS

install: all
	mkdir -p $(LIBDIR)/bin
	mkdir -p $(LIBDIR)/modules/cce/dict
	$(INSTALL) -o root -g $(GROUP) -m 755 -d $(LIBDIR)
	$(INSTALL) -s -o root -g $(GROUP) -m 755 $(EXECPROGS) $(LIBDIR)/bin
	$(INSTALL) -o root -g $(GROUP) -m 644 *.tab* $(LIBDIR)/modules/cce/dict
	$(INSTALL) -o root -g $(GROUP) -m 644 pinyin.map $(LIBDIR)/modules/cce/dict
	$(INSTALL) -o root -g $(GROUP) -m 644 *.def $(LIBDIR)/modules/cce/dict

ifeq (.depend, $(wildcard .depend))
include .depend
endif

